package com.kfm.base.date.d0825.am;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Date;

public class Demo04 {

    public static void main(String[] args) {
        /**
         * Date <--> LocalDateTime
         */
        Date date = new Date();
        // 转换成 Instant (瞬间)
        Instant instant = date.toInstant();
        // 加上时区信息
//        ZoneId zoneId = ZoneId.systemDefault();
        ZoneId zoneId = ZoneId.of("Asia/Shanghai");
//        System.out.println(zoneId);
        ZonedDateTime zonedDateTime = instant.atZone(zoneId);

        // 转换成 LocalDate  LocalTime  LocalDateTime
        LocalDateTime localDateTime = zonedDateTime.toLocalDateTime();
        System.out.println(localDateTime);



        // LocalDateTime  -->  Date
        zoneId = ZoneId.systemDefault();

        // 获取到 ZonedDateTime 对象
        ZonedDateTime zonedDateTime1 = localDateTime.atZone(zoneId);
        zonedDateTime1 = ZonedDateTime.of(localDateTime, zoneId);

        // 转换成 Instant 瞬间
        Instant instant1 = zonedDateTime1.toInstant();

        Date from = Date.from(instant1);
        System.out.println(from);

    }
}
